home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wlib11_2.zip / EXAMPLES.EXE / EXAM79.C < prev    next >
C/C++ Source or Header  |  1991-03-13  |  3KB  |  111 lines

  1.   #include <stdio.h>
  2.   #include <string.h>
  3.   #include "window.h"
  4.  
  5.   #define NORM  CREATE_VIDEO_ATTRIBUTE(black,white)
  6.  
  7.                     /* define filename characters */
  8.   #define FILENAMECHARS  "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
  9.  
  10.   VWPOINTER vw;          /* virtual window pointer */
  11.   WPOINTER w;            /* Window pointer */
  12.   char filename[26];
  13.   FILE *infile;          /* input file handle */
  14.  
  15.   main()
  16.   {
  17.     unsigned int i,j,row,col;
  18.     WindowInitializeSystem();
  19.     WindowSaveInitial(0);
  20.  
  21.     /* set up a Type 0 virtual window */
  22.     vw = VirtualInitialize(NOATTRIBUTE,  /* virtual window type number */
  23.                            200,      /* Number of rows */
  24.                            80,      /* Number of cols */
  25.                            0);      /* Attribute      */
  26.  
  27.     /* set up viewport window */
  28.     w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
  29.     WindowOpen(w);
  30.     WindowDisplay(w,1,NOEFFECT);
  31.  
  32.     /* read a file name */
  33.     read_file();
  34.  
  35.     /* display file in viewport */
  36.     WindowAssignToVirtual(w,vw,1,1);      /* Assign viewport to virtual window */
  37.  
  38.     row = col = 1;
  39.     flush_keyboard_flag = TRUE;        /* Set keyboard flush to TRUE */
  40.     while (1)
  41.     {
  42.       switch (GET_KEY())    /* Keep getting keys until ESCAPE key is hit */
  43.       {
  44.          case UARROW:      /* Move viewport up 1 line */
  45.  
  46.            if (row > 1)
  47.              WindowPositionViewport(w,--row,col);
  48.          break;
  49.          case DARROW:      /* Move viewport down 1 line */
  50.            if (row < 189)
  51.              WindowPositionViewport(w,++row,col);
  52.          break;
  53.  
  54.          case LARROW:      /* Move viewport left 1 line */
  55.            if (col > 1)
  56.              WindowPositionViewport(w,row,--col);
  57.          break;
  58.          case RARROW:      /* Move viewport right 1 line */
  59.            if (col < 69)
  60.              WindowPositionViewport(w,row,++col);
  61.          break;
  62.          case ESC:         /* End program */
  63.  
  64.            close_all();
  65.          break;
  66.       }
  67.     }
  68.   }
  69.  
  70.  
  71.   read_file()         /* Gets a filename and displays it in the window */
  72.   {
  73.      int ch;
  74.      unsigned r = 1, c = 1;
  75.      filename[0] = 0;
  76.      WindowWriteString(w,"Please enter a file name: ",1,1);
  77.      WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
  78.      if ((infile = fopen(filename,"r")) == NULL)
  79.      {
  80.        WindowMoveCursor(w,3,1);
  81.        WindowPrintf(w,"File name %s does not exist\nPress a key to continue",
  82.                 filename);
  83.        GET_KEY();
  84.        close_all();
  85.      }
  86.      else
  87.      while(1)         /* Read characters into virtual window */
  88.      {
  89.        ch = fgetc(infile);
  90.        if (feof(infile))
  91.          break;
  92.        if (ch != '\n')
  93.          VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
  94.        else
  95.        {
  96.          r++;
  97.          c=1;
  98.  
  99.        }
  100.      }
  101.      fclose(infile);
  102.   }
  103.  
  104.  
  105.  
  106.   close_all()
  107.   {
  108.     WindowClose(w,NOEFFECT);
  109.     exit(0);
  110.   }
  111.